package com.hlingsoft.kkh.action.v20;

import com.hlingsoft.kkh.action.BaseAction;
import com.hlingsoft.kkh.entity.EventComments;
import com.hlingsoft.kkh.entity.Report;
import com.hlingsoft.kkh.util.Common;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by selbylei on 2015/7/1.
 */
@Controller
@RequestMapping("v20/report")
public class ReportAction extends BaseAction {


    /**
     * 举报
     * @param myId        举报人
     * @param reportRs  举报原因
     * @param content     举报说明
     * @param eventCommentsId    举报跟帖id
     * @param request
     * @return
     */
    @RequestMapping(value = "/add.json")
    @ResponseBody
    public Map<String, Object> add(
            @RequestParam(value = "myId") long myId,
            @RequestParam(value = "reportRs") String reportRs,
            @RequestParam(value = "content",required = false) String content,
            @RequestParam(value = "eventCommentsId") long eventCommentsId,
            HttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            Date now = new Date();
            if (request.getMethod().equalsIgnoreCase("get")){
                reportRs=Common.encodeStr(reportRs);
                if (content!=null){
                    content=Common.encodeStr(content);
                }
            }
            Report report = new Report();
            report.setMyId(myId);
            report.setReportRs(reportRs);
            report.setContent(content);

            EventComments eventComments = eventCommentsDao.getCommentsListById(eventCommentsId);
            report.setToId(eventComments.getAppUserId());
            report.setEventsId(eventComments.getEventId());
            report.setEventCommentsId(eventCommentsId);
            report.setStatus(1);  //默认未处理
            report.setCreateTime(now);
            report.setUpdateTime(now);
            reportDao.addReport(report);
            resultMap.put("report",report);
            resultMap.put("result", true);
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", false);
        }
        return resultMap;
    }
}
